package com.example.kotlinlearn

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.kotlinlearn.recycler.ListItem
import com.example.kotlinlearn.recycler.ListItemAdapter

class RecyclerViewActivity : BaseActivity() {

    private val itemList = ArrayList<ListItem>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_recycler_view)
        initItemList()
        val layoutManager = LinearLayoutManager(this)
        //水平排列
        //layoutManager.orientation = LinearLayoutManager.HORIZONTAL
        val recyclerView:RecyclerView = findViewById(R.id.recyclerView)
        recyclerView.layoutManager = layoutManager
        val adapter = ListItemAdapter(itemList)
        recyclerView.adapter = adapter
    }

    private fun initItemList(){
        repeat(4){
            itemList.add(ListItem("易志豪",R.drawable.ic_launcher_foreground))
            itemList.add(ListItem("jslfjslkfj",R.drawable.ic_launcher_foreground))
            itemList.add(ListItem("游客前来语言",R.drawable.ic_launcher_foreground))
            itemList.add(ListItem("十分罕见粉红是",R.drawable.ic_launcher_foreground))
            itemList.add(ListItem("副教授副教授",R.drawable.ic_launcher_foreground))
        }
    }
}